package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.bean.UserLocationMsg;
import com.a3dweijing.wetouch2.callback.OnClick;

import java.util.List;

/**
 * Created by Yxd on 2018/3/26.
 */

public class LocationListAdapter extends RecyclerView.Adapter<LocationListAdapter.MyViewHolder> {


    OnClick click;
    List<UserLocationMsg.AddressBean> beens;

    public LocationListAdapter(OnClick click, List<UserLocationMsg.AddressBean> beens) {
        this.click = click;
        this.beens = beens;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_location, parent, false));
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.name.setText(beens.get(position).getConsignee());
        holder.tel.setText(beens.get(position).getConsignee_tel());
        holder.address.setText(beens.get(position).getAddress_name());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (click != null) {
                    click.onclick(position, beens.get(position));
                }
            }
        });
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (click != null) {
                    click.onclick(view.getId(), beens.get(position));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return beens.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        TextView tel;
        TextView address;
        ImageView delete;

        public MyViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.location_user_name);
            tel = itemView.findViewById(R.id.location_user_tel);
            address = itemView.findViewById(R.id.location_user_address);
            delete = itemView.findViewById(R.id.location_user_delete);
        }
    }


}
